package com.uenpay.im.ui.old.activity.wallet;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.qiyunxin.android.http.HttpInvokeResultCode;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.ui.old.activity.transfer.TransferEntity;
import com.uenpay.im.ui.old.activity.transfer.TransferHandle;
import com.uenpay.im.weight.ZProgressHUD;
import com.uenpay.util.app.base.BaseActivity;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-6 下午6:17:20
 * @version 1.0
 * @function 收支详情
 */
public class BillDetailActivity extends BaseActivity {

	private TextView amount_tv, reason_tv, create_date_tv, type_tv,
			transaction_number, left_change, tran_type;
	private ZProgressHUD zProgressHUD;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View bindView() {
		return null;
	}

	@Override
	public int bindLayout() {
		return R.layout.activity_bill_detail_layout;
	}

	@Override
	public void initView(View view) {
		String turnoverid = getIntent().getStringExtra("turnoverid");
		initView();
		initListener();
		getTransferDetail(turnoverid);
	}

	protected void initView() {
		zProgressHUD = new ZProgressHUD(this);
		setTitle("账单详情");
		amount_tv = (TextView) findViewById(R.id.amount_tv);
		tran_type = (TextView) findViewById(R.id.tran_type);
		reason_tv = (TextView) findViewById(R.id.reason_tv);
		create_date_tv = (TextView) findViewById(R.id.create_date_tv);
		type_tv = (TextView) findViewById(R.id.type_tv);
		transaction_number = (TextView) findViewById(R.id.transaction_number);
		left_change = (TextView) findViewById(R.id.left_change);
	}

	protected void initListener() {
	}

	/**
	 * 获取转账详情
	 *
	 * @param turnoverid
	 */
	private void getTransferDetail(String turnoverid) {
		zProgressHUD.show();
		TransferHandle.getTransferDetail(turnoverid, new TransferHandle.ITarsferListener() {

			@Override
			public void getTarsferResult(int status, String msg,
										 TransferEntity mTransferEntity) {
				zProgressHUD.dismiss();
				if (status == HttpInvokeResultCode.RESULT_OK) {
					if (mTransferEntity != null) {
						if (!TextUtils.isEmpty(mTransferEntity.amount)
								&& mTransferEntity.amount.startsWith("-")) {
							tran_type.setText(R.string.out_amount);
							type_tv.setText(R.string.cost);
						} else {
							tran_type.setText(R.string.in_amount);
							type_tv.setText(R.string.income);
						}
						amount_tv.setText(mTransferEntity.amount.replace("-",
								""));
						create_date_tv.setText(mTransferEntity.createtime);
						transaction_number.setText(mTransferEntity.turnoverid);
						left_change.setText(mTransferEntity.leftamount);
						if (!TextUtils.isEmpty(mTransferEntity.memo)) {
							reason_tv.setText(mTransferEntity.memo);
						}
					}
				} else if (!TextUtils.isEmpty(msg)) {
					IMApplication.showToast(msg);
					zProgressHUD.dismiss();
				}
			}
		});
	}

	@Override
	public void onBackPressed() {
		finish();
		super.onBackPressed();
	}

	@Override
	protected void onDestroy() {
		IMApplication.getInstance().removeActivity(this);
		super.onDestroy();
	}
}
